#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    bool hasCycle(ListNode* head)
    {
        ListNode* last, * fast;
        last = fast = head;
        while (fast != nullptr && fast->next != nullptr)
        {
            last = last->next;
            fast = fast->next->next;
            if (last == fast)
                return true;
        }
        return false;
    }
};

